package br.com.arosa.dao;

import java.util.*;
import java.sql.*;
import br.com.easynet.database.DataSet;
import br.com.jdragon.dao.*;
import br.com.arosa.transfer.*;

public class Tb_fornecedorDAO extends ObjectDAO { 
	 public Tb_fornecedorDAO(DAOFactory dao) throws Exception {
		 setDAOFactory(dao);
 		 con = dao.create();
 	 }

	 public void insert(Tb_fornecedorT tb_fornecedorT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "insert into tb_fornecedor  ( id_fornecedor, id_cidade, nome, razao_social, inscricao_estadual, cnpj, endereco, numero, bairro, complemento, telefone, email, site) values ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_fornecedor());
			 pStmt.setObject(2, tb_fornecedorT.getId_cidade());
			 pStmt.setObject(3, tb_fornecedorT.getNome());
			 pStmt.setObject(4, tb_fornecedorT.getRazao_social());
			 pStmt.setObject(5, tb_fornecedorT.getInscricao_estadual());
			 pStmt.setObject(6, tb_fornecedorT.getCnpj());
			 pStmt.setObject(7, tb_fornecedorT.getEndereco());
			 pStmt.setObject(8, tb_fornecedorT.getNumero());
			 pStmt.setObject(9, tb_fornecedorT.getBairro());
			 pStmt.setObject(10, tb_fornecedorT.getComplemento());
			 pStmt.setObject(11, tb_fornecedorT.getTelefone());
			 pStmt.setObject(12, tb_fornecedorT.getEmail());
			 pStmt.setObject(13, tb_fornecedorT.getSite());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void update(Tb_fornecedorT tb_fornecedorT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "update tb_fornecedor set  id_cidade=?, nome=?, razao_social=?, inscricao_estadual=?, cnpj=?, endereco=?, numero=?, bairro=?, complemento=?, telefone=?, email=?, site=?  where  id_fornecedor=?";
 			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_cidade());
			 pStmt.setObject(2, tb_fornecedorT.getNome());
			 pStmt.setObject(3, tb_fornecedorT.getRazao_social());
			 pStmt.setObject(4, tb_fornecedorT.getInscricao_estadual());
			 pStmt.setObject(5, tb_fornecedorT.getCnpj());
			 pStmt.setObject(6, tb_fornecedorT.getEndereco());
			 pStmt.setObject(7, tb_fornecedorT.getNumero());
			 pStmt.setObject(8, tb_fornecedorT.getBairro());
			 pStmt.setObject(9, tb_fornecedorT.getComplemento());
			 pStmt.setObject(10, tb_fornecedorT.getTelefone());
			 pStmt.setObject(11, tb_fornecedorT.getEmail());
			 pStmt.setObject(12, tb_fornecedorT.getSite());
			 pStmt.setObject(13, tb_fornecedorT.getId_fornecedor());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void delete(Tb_fornecedorT tb_fornecedorT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "delete from tb_fornecedor where  id_fornecedor=?";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_fornecedor());
			 pStmt.execute();
		 } catch (Exception e)  {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 private List<Tb_fornecedorT> resultSetToObjectTransfer(ResultSet rs) throws Exception { 
		 List<Tb_fornecedorT> objs = new Vector();
		 while (rs.next()) { 
 			 Tb_fornecedorT tb_fornecedorT = new Tb_fornecedorT();
			 tb_fornecedorT.setId_fornecedor(rs.getInt("id_fornecedor"));
			 tb_fornecedorT.setId_cidade(rs.getInt("id_cidade"));
			 tb_fornecedorT.setNome(rs.getString("nome"));
			 tb_fornecedorT.setRazao_social(rs.getString("razao_social"));
			 tb_fornecedorT.setInscricao_estadual(rs.getString("inscricao_estadual"));
			 tb_fornecedorT.setCnpj(rs.getString("cnpj"));
			 tb_fornecedorT.setEndereco(rs.getString("endereco"));
			 tb_fornecedorT.setNumero(rs.getString("numero"));
			 tb_fornecedorT.setBairro(rs.getString("bairro"));
			 tb_fornecedorT.setComplemento(rs.getString("complemento"));
			 tb_fornecedorT.setTelefone(rs.getString("telefone"));
			 tb_fornecedorT.setEmail(rs.getString("email"));
			 tb_fornecedorT.setSite(rs.getString("site"));
			 objs.add(tb_fornecedorT);
 		 }
 		 return objs; 
 	 }
	 public List<Tb_fornecedorT> getAll() throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor"; 
			 pStmt = con.prepareStatement(sql);
			 rs = pStmt.executeQuery();
 			 List<Tb_fornecedorT> list = resultSetToObjectTransfer(rs);
 			 return list; 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getById(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  id_fornecedor=?"; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_fornecedor());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getById_fornecedor(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  id_fornecedor = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_fornecedor());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getById_cidade(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  id_cidade = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_fornecedorT.getId_cidade());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByNome(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(nome) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getNome()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByRazao_social(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(razao_social) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getRazao_social()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByInscricao_estadual(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(inscricao_estadual) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getInscricao_estadual()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByCnpj(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(cnpj) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getCnpj()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByEndereco(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(endereco) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getEndereco()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByNumero(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(numero) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getNumero()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByBairro(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(bairro) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getBairro()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByComplemento(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(complemento) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getComplemento()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByTelefone(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(telefone) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getTelefone()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getByEmail(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(email) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getEmail()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_fornecedorT> getBySite(Tb_fornecedorT tb_fornecedorT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_fornecedor where  Upper(site) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_fornecedorT.getSite()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 

 }